package com.job.dao.Impl;

import com.job.dao.ProfessionDao;
import com.job.model.Profession;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import javax.management.Query;
import java.util.List;
@Repository("professionDao")
public class ProfessionDaoImpl implements ProfessionDao {
    private SessionFactory sessionFactory;

    /**
     * 获取所有的岗位分类
     *
     * @return
     */
    @Override
    public List<Profession> getAllProfession() {
        Session session=sessionFactory.openSession();
        org.hibernate.query.Query query=session.createQuery("from Profession ");
        query.getComment();
       List list= query.getResultList();
       session.close();
       return list;
    }

    /**
     * 根据类型获取工作分类名称
     *
     * @param sorId 分类代码1-3
     * @return
     */
    @Override
    public List<Profession> getAllProfession(int sorId) {
        Session session=sessionFactory.openSession();
       org.hibernate.query.Query query= session.createQuery("from Profession as p where p.sortId=:sortId");
       query.setParameter("sortId",sorId);
       query.getComment();
       List<Profession> list=query.getResultList();
       session.close();
       return list;

    }

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }
}
